$OpenBSD: patch-src_jgrep_c,v 1.1 2007/10/26 21:42:18 ajacoutot Exp $
--- src/jgrep.c.orig	Mon Jul  3 16:52:28 1995
+++ src/jgrep.c	Fri Oct 26 23:36:44 2007
@@ -38,17 +38,19 @@ static int o_noerr = FALSE;		/* -s */
 static int o_nomat = FALSE;		/* -v */
 static int o_wsrch = FALSE;		/* -w */
 static int o_scode = FALSE;		/* -C */
+static int o_sline = FALSE;		/* -n */
 
 	static void
 usage()
 {
 	fprintf(stderr, "Jgrep/%s by ann@mrit.mei.co.jp\n", JpVersion);
-	fprintf(stderr, "Usage: jgrep [ -cilsvwCNJESX., ] pattern [filename ...]\n");
+	fprintf(stderr, "Usage: jgrep [ -cilsvnwCNJESX., ] pattern [filename ...]\n");
 	fprintf(stderr, "	-c     Print only a count of the lines.\n");
 	fprintf(stderr, "	-i     Ignore case.\n");
 	fprintf(stderr, "	-l     Print only file name.\n");
 	fprintf(stderr, "	-s     Suppress error message.\n");
 	fprintf(stderr, "	-v     Print lines not match with the pattern.\n");
+	fprintf(stderr, "	-n     Print line number.\n");
 	fprintf(stderr, "	-w     Search \\<pattern\\>.\n");
 	fprintf(stderr, "	-C     Print kanji code.\n");
 	fprintf(stderr, "	-N -J -E -S -X	\n");
@@ -104,7 +106,7 @@ main(argc, argv)
 	jread = jdisp = JP_NONE;
 #endif
 
-	if (argc > 1 && argv[0][0] == '-')
+	while (argc > 1 && argv[0][0] == '-')
 	{
 		char *cp;
 		for(cp = argv[0] + 1; *cp; cp++)
@@ -127,6 +129,10 @@ main(argc, argv)
 				o_noerr = TRUE;
 				break;
 
+			case 'n':
+				o_sline = TRUE;
+				break;
+
 			case 'v':
 				o_nomat = TRUE;
 				break;
@@ -268,9 +274,11 @@ do_grep(fp, prog, fname)
 	char *fname;
 {
 	int count;
+	int nline;
 
 	reg_ic = o_icase;
 	count = 0;
+	nline = 0;
 
 	reset_jcount();
 
@@ -282,6 +290,9 @@ do_grep(fp, prog, fname)
 		if (fgets(Line, IOSIZE, fp) == NULL)
 			break;
 
+		if (strchr(Line, '\n'))
+	    	nline++;
+
 		len = strlen(Line);
 		len = kanjiconvsfrom(Line, len, IObuff, IOSIZE * 2, NULL,
 															jread, NULL);
@@ -294,6 +305,8 @@ do_grep(fp, prog, fname)
 			{
 				if (fname)
 					printf("%s:", fname);
+				if (o_sline)
+					printf("%d:", nline);
 				if (o_scode)
 					printf("(%c)", judge_jcode(jread));
 				if (o_nonly)
